<script setup>
import { ref, reactive } from 'vue'
import { UserFilled, Lock } from '@element-plus/icons-vue'
import Vcode from 'vue3-puzzle-vcode'
import rules from '@/utils/Login/formRules'
import { useRouter } from 'vue-router'
const router = useRouter()
const form = ref({
  username: '',
  password: ''
})

const formRef = ref(null)
// 拼图验证函数
const isShow = ref(false)

const onSuccess = () => {
  isShow.value = false
  router.push('/')
}
// 登录表单提交
function onLogin() {
  formRef.value.validate(async (valid) => {
    if (valid) {
      isShow.value = true
    }
  })
}
</script>

<template>
  <div class="login-wrapper">
    <div class="form-wrapper">
      <div class="form-title">欢迎登录</div>
      <div class="form-contennt">
        <el-form :model="form" label-width="auto" :rules="rules" ref="formRef">
          <el-form-item prop="username">
            <el-input v-model="form.username" placeholder="用户名" :prefix-icon="UserFilled" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="form.password" placeholder="密码" :prefix-icon="Lock" />
          </el-form-item>
        </el-form>
      </div>
      <div class="form-footer">
        <el-button type="primary" class="login-btn" @click="onLogin">登录/注册</el-button>
      </div>
    </div>
    <Vcode :show="isShow" @success="onSuccess" @close="onClose" :sliderSize="40" />
  </div>
</template>

<style lang="scss" scoped>
.login-wrapper {
  position: relative;
  align-items: center;
  width: 100vw;
  height: 100vh;
  background: url('@/assets/image/login/login-bg.png') no-repeat center/100% 100%;
  .form-wrapper {
    position: absolute;
    right: 8%;
    top: 25%;
    width: 350px;
    height: 400px;
    background-color: white;
    border-radius: 20px;
    overflow: hidden;
    .form-title {
      font-size: 30px;
      font-family: 'PMZDR';
      letter-spacing: 10px;
      color: rgb(10, 149, 241);
      margin-top: 15px;
      animation: formTitleColor 4s infinite alternate;
    }
    .form-contennt {
      padding: 30px;
      padding-bottom: 10px;
    }
    .login-btn {
      width: 290px;
      border-radius: 5px;
      height: 40px;
      font-size: 18px;
      &:active {
        transform: translateY(10px);
      }
    }
  }
}
:deep(.el-input__wrapper) {
  width: 300px;
  height: 40px;
  border-radius: 20px;
  .el-input__prefix {
    font-size: 20px;
    margin-right: 7px;
    margin-left: 3px;
  }
}
:deep(.el-form-item) {
  margin-bottom: 25px;
}
</style>
